package core

import (
	"encoding/json"
	"go_test/customProxy"
	"go_test/models"
	"math/rand"
	"net/http"
	"time"
)

func InitSeed() {
	rand.Seed(time.Now().UnixNano())
}

const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

func RandStringBytes(n int) string {
	b := make([]byte, n)
	for i := range b {
		b[i] = letterBytes[rand.Intn(len(letterBytes))]
	}
	return string(b)
}
func GetUa(link models.LinkReq) string {
	if link.VersionType == "ALL" {
		return models.GetRandomIosDevice().BuildUa()
	} else if link.VersionType == "LOW" {
		return models.GetRandomIosDeviceLow().BuildUa()
	} else if link.VersionType == "HIGH" {
		return models.GetRandomIosDeviceHigh().BuildUa()
	} else if link.VersionType == "CUSTOM" {
		//TODO 未实现
		//return models.GetRandomIosDevice().BuildUa()
	}
	return ""
}
func queryIP(client *http.Client, ua string) (string, error) {
	var res, err = customProxy.Req(client, customProxy.CreateRequest("http://ip-api.com/json", ua))
	var result map[string]interface{}
	var queryValue = ""
	if err == nil {
		err = json.Unmarshal([]byte(res), &result)
		queryValue = result["query"].(string)
	}
	return queryValue, err
}
